//
//  GHDoctorComtroller.m
//  guahao
//
//  Created by osx on 16/10/6.
//  Copyright © 2016年 osx. All rights reserved.
//

#import "GHDoctorComtroller.h"
#import "HomeViewController.h"
#import "UIViewController+MMDrawerController.h"
#import "UIColor+randomColor.h"
#import "GHRightViewControler.h"
#import "GHKeShi.h"
#import "Masonry.h"
#import "DefineTools.h"
#import "UIView+Extension.h"
#import "GHZiXunYiShi.h"
#import "GHSearch.h"
#import "GHKuSuJiuYi.h"
#import "UILabel+Extension.h"
#import "GHNetWorkTools.h"
#import "UIButton+Extension.h"
//#import "LoopImageViewController.h"
#import "SDCycleScrollView.h"
#import "ViewController.h"
#import "GHLBController.h"
#import "GHMyGuaHaoController.h"

@interface GHDoctorComtroller ()<SDCycleScrollViewDelegate>

@property (nonatomic,strong)UIButton *keshiGH;
@property (nonatomic ,strong)UIButton *kuaiSiJiuYi;
@property (nonatomic, strong)UIButton *ziXunYishi;
@property (nonatomic, strong)UIButton *search;
@property (nonatomic, strong)UIView *titleview;
@property (nonatomic, strong)SDCycleScrollView *loopView;

//@property (nonatomic, )

@end

@implementation GHDoctorComtroller

-(SDCycleScrollView *)loopView{
    
    if (!_loopView) {
        
        NSArray *images = @[[UIImage imageNamed:@"h1.jpg"],
                            [UIImage imageNamed:@"h2.jpg"],
                            [UIImage imageNamed:@"h3.jpg"],
                            [UIImage imageNamed:@"h4.jpg"]
                            ];
        
        
        
        CGFloat w = self.view.bounds.size.width;
        
        // 本地加载 --- 创建不带标题的图片轮播器
        SDCycleScrollView *cycleScrollView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, w, 180) imagesGroup:images];
        
        cycleScrollView.infiniteLoop = YES;
        cycleScrollView.delegate = self;
        cycleScrollView.pageControlStyle = SDCycleScrollViewPageContolStyleAnimated;
        [self.view addSubview:cycleScrollView];
        //         --- 轮播时间间隔，默认1.0秒，可自定义
        //cycleScrollView.autoScrollTimeInterval = 4.0;
        
        
    }
    return _loopView;
}

-(UIView *)titleview{
    
    if (!_titleview) {
        
        CGFloat GHTitleMargin = 10;
        _titleview = [[UIView alloc] init];
        
        UIButton *lb1 = [UIButton initWithTitle:@"123" fontsize:15 color:[UIColor blackColor]];
        [lb1 addTarget:self action:@selector(clickLb) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *lb2 = [UIButton initWithTitle:@"123" fontsize:15 color:[UIColor blackColor]];
        [lb2 addTarget:self action:@selector(clickLb) forControlEvents:UIControlEventTouchUpInside];
        
        
        [_titleview addSubview:lb1];
        [_titleview addSubview:lb2];
        
        [lb1 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_titleview.mas_top).with.offset(GHTitleMargin);
            make.width.equalTo(_titleview.mas_width);
        }];
        [lb2 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(lb1.mas_bottom).with.offset(GHTitleMargin);
            make.width.equalTo(lb1.mas_width);
            make.bottom.equalTo(_titleview.mas_bottom).with.offset(-GHTitleMargin);
            
        }];
        
    }
    
    return _titleview;
}

-(void)clickLb{
    
    NSLog(@"click--Lb");
    
    GHLBController *lbvc = [[GHLBController alloc] init];
    [self.navigationController pushViewController:lbvc animated:YES];
}


-(UIButton *)keshiGH{
    
    if (!_keshiGH) {
        _keshiGH = [[UIButton alloc] init];
        [_keshiGH addTarget:self action:@selector(didkeshiGH) forControlEvents:UIControlEventTouchUpInside];
        _keshiGH.backgroundColor = [UIColor randomColor];
        
        [_keshiGH setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal];
        
        [_keshiGH sizeToFit];
        
        
    }
    
    return _keshiGH;
}
-(void)didkeshiGH{
    
    GHMyGuaHaoController *keshiVC = [[GHMyGuaHaoController alloc] init];
    [self.navigationController pushViewController:keshiVC animated:YES];
}
-(UIButton *)kuaiSiJiuYi{
    
    if (!_kuaiSiJiuYi) {
        _kuaiSiJiuYi = [[UIButton alloc] init];
        
        [_kuaiSiJiuYi addTarget:self action:@selector(didkuaiSiJiuYi) forControlEvents:UIControlEventTouchUpInside];
        _kuaiSiJiuYi.backgroundColor = [UIColor randomColor];
        
        // [_kuaiSiJiuYi setBackgroundImage:[UIImage imageNamed:@"test"]   forState:UIControlStateHighlighted];
        [_kuaiSiJiuYi setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal];
        [_kuaiSiJiuYi sizeToFit];
        
    }
    
    return _kuaiSiJiuYi;
}
-(void)didkuaiSiJiuYi{
    GHKuSuJiuYi *ksVC = [[GHKuSuJiuYi alloc] init];
    [self.navigationController pushViewController:ksVC animated:YES];
}
-(UIButton *)ziXunYishi{
    
    if (!_ziXunYishi) {
        _ziXunYishi = [[UIButton alloc] init];
        [_ziXunYishi addTarget:self action:@selector(didziXunYishi) forControlEvents:UIControlEventTouchUpInside];
        _kuaiSiJiuYi.backgroundColor = [UIColor randomColor];
        // [_ziXunYishi setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateHighlighted];
        [_ziXunYishi setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal];
        [_ziXunYishi sizeToFit];
    }
    
    return _ziXunYishi;
}
-(void)didziXunYishi{
    
    GHZiXunYiShi *zxVC = [[GHZiXunYiShi alloc] init];
    [self.navigationController pushViewController:zxVC animated:YES];
}
-(UIButton *)search{
    
    if (!_search) {
        _search = [[UIButton alloc] init];
        [_search addTarget:self action:@selector(didsearch) forControlEvents:UIControlEventTouchUpInside];
        _search.backgroundColor = [UIColor randomColor];
        // [_search setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateHighlighted];
        [_search setBackgroundImage:[UIImage imageNamed:@"test"] forState:UIControlStateNormal];
        [_search sizeToFit];
    }
    
    return _search;
}
-(void)didsearch{
    
    GHSearch *seVC = [[GHSearch alloc] init];
    [self.navigationController pushViewController:seVC animated:YES];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self test];
    [self setUI];
    
    
}
-(void)test{
    
    NSURL *url=@"hospital";
    
    [[GHNetWorkTools sharedTools] GET:url parameters:NULL progress:^(NSProgress * _Nonnull downloadProgress) {
        NSLog(@"chenggong");
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //NSLog(@"susses");
        NSLog(@"susses----:%@",responseObject);
        
        NSDictionary *result = [[NSDictionary alloc] init];
        
        if ([responseObject isKindOfClass:[NSData class]]){
            
            result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
            
        }else{
            
            result = responseObject;
        }
        NSString *str = [result valueForKey:@"HospitalInfo"];
        
        NSLog(@"result----???????:%@",str);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"fail-----------");
    }];
    
}


-(void)setUI{
    
    CGFloat GHViewMargin = 30;
    
    self.view.backgroundColor = [UIColor randomColor];
    
    UIBarButtonItem * leftMenuBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"l"] style:UIBarButtonItemStylePlain  target:self action:@selector(didClickLeftMenuBtn)];
    self.navigationItem.leftBarButtonItem = leftMenuBtn;
    
    
    UIBarButtonItem * rightMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"xianhua"] style:UIBarButtonItemStylePlain target:self action:@selector(didClickRightMenuBtn)];
    self.navigationItem.rightBarButtonItem = rightMenuBtn;
    
    // UIButton *test = [[UIButton alloc] init];
    // [test setImage:[UIImage imageNamed:@"xianhua"] //forState:UIControlStateNormal];
    ////[test sizeToFit];
    // [self.view addSubview:test];
    
    //[test mas_makeConstraints:^(MASConstraintMaker *make) {
    //    make.right.left.equalTo(self.view);
    //}];
    
    [self.view addSubview:self.keshiGH];
    [self.view addSubview:self.kuaiSiJiuYi];
    [self.view addSubview:self.ziXunYishi];
    [self.view addSubview:self.search];
    [self.view addSubview:self.titleview];
    [self.view addSubview:self.loopView];
    
    
    
    
    [self.ziXunYishi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-GHViewMargin) ;
        make.left.equalTo(self.view.mas_left).with.offset(GHViewMargin);
        
        
    }];
    [self.search mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.ziXunYishi.mas_bottom);
        make.right.equalTo(self.view.mas_right).with.offset(-GHViewMargin);
        make.width.equalTo(self.ziXunYishi);
    }];
    [self.keshiGH mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.ziXunYishi.mas_top).offset(-GHViewMargin);
        make.left.equalTo(self.ziXunYishi.mas_left);
        
    }];
    [self.kuaiSiJiuYi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.keshiGH.mas_bottom);
        make.right.equalTo(self.search.mas_right);
    }];
    [self.titleview mas_makeConstraints:^(MASConstraintMaker *make) {
        // make.bottom.equalTo(self.keshiGH.mas_top).with.offset(-GHViewMargin);
        make.bottom.equalTo(self.keshiGH.mas_top);
        make.width.equalTo(self.view.mas_width);
        // make.top.equalTo(self.).with.offset(200);
    }];
    [self.loopView mas_makeConstraints:^(MASConstraintMaker *make) {
        //make.top.equalTo(self.view.mas_top).with.offset(GHViewMargin);
        make.top.equalTo(self.view.mas_top).with.offset(-GHViewMargin);
        make.width.equalTo(self.view.mas_width);
        make.bottom.equalTo(self.titleview.mas_top).with.offset(GHViewMargin);
    }];
    
    //  NSLog(@"%@",self.ziXunYishi);
    //  NSLog(@"image:%@",self.ziXunYishi.imageView.image);
    //  NSLog(@"%@",self.view);
    //  NSLog(@"%@",self.view.subviews);
}


-(void)didClickLeftMenuBtn{
    NSLog(@"首页左边按钮点击事件[");
    [self.mm_drawerController toggleDrawerSide:MMDrawerSideLeft animated:YES completion:nil];
}
-(void)didClickRightMenuBtn{
    
    GHRightViewControler *rightVC = [[GHRightViewControler alloc] init];
    [self.navigationController pushViewController:rightVC  animated:YES];
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
